package com.maolong.publish;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class PublishProductor {
    private static final String EXCHANGE= "publish_exchange";
    private static final String QUEUE= "publish_queue1";
    private static final String QUEUE2= "publish_queue2";

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("182.92.151.172");
        factory.setUsername("maolong");
        factory.setPassword("123456");

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.exchangeDeclare(EXCHANGE, "fanout");
        channel.queueDeclare(QUEUE, false, false, false, null);
        channel.queueDeclare(QUEUE2, false, false, false, null);

        channel.queueBind(QUEUE, EXCHANGE, "");
        channel.queueBind(QUEUE2, EXCHANGE, "");

        for (int i = 0; i < 10; i++) {
            String message = "hello world"+i;
            channel.basicPublish(EXCHANGE,"",null, message.getBytes("UTF-8"));

        }



    }
}
